package com.ddyx.service.product.app.system.controller;


import com.ddyx.common.base.controller.BaseController;
import com.ddyx.service.product.api.entity.Goods;
import com.ddyx.service.product.api.vo.GoodsVo;
import com.ddyx.service.product.app.system.service.IGoodsService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 商品 前端控制器
 * </p>
 *
 * @author agula
 * @since 2019-08-06
 */

@Validated
@Api(value = "商品管理模块", tags = "商品管理")
@RestController
@RequestMapping("/goods")
public class GoodsController extends BaseController {

    @Resource
    private IGoodsService goodsService;


    @ApiOperation(value="商品列表接口", notes="分页查询商品列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "分页页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "每页条数", required = true, dataType = "int", paramType = "query")
    })
    @RequestMapping(value = "/getList", method = RequestMethod.GET)
    public Object getList(@NotNull @RequestParam Integer page, @NotNull @RequestParam Integer size) {
        Page<Object> pageHelper = PageHelper.startPage(page, size);
        List<Goods> list = goodsService.getList();
        int total = (int) pageHelper.getTotal();
        return successResult(list, total);
    }



    @ApiOperation(value="商品添加接口", notes="提交商品信息进行添加")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Object add(@Valid @RequestBody GoodsVo goodsVo) {
        goodsService.add(goodsVo);
        return successResult();
    }



    @ApiOperation(value="获取商品资料接口", notes="获取指定资料")
    @RequestMapping(value = "/getProductInfo/{productId}", method = RequestMethod.GET)
    public Object getProductInfo(@NotNull @PathVariable int productId) {

        return successResult();
    }


    @ApiOperation(value="获取商品资料", notes="获取指定资料")
    @RequestMapping(value = "/product-info-by-id/{productId}", method = RequestMethod.GET)
    public Object getProductById(@NotNull @PathVariable int productId) {

        return successResult(productId);
    }


}

